package net.airtheva.uniqueTask4;

import android.app.Notification;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.support.v4.app.NotificationCompat;
import android.widget.RemoteViews;

public class ControlNotification {
	
	public static final int REQUEST_CODE_ENTRY_ACTIVITY = 0;
	public static final int REQUEST_CODE_CONTROL = 1;
	
	Context context;
	
	NotificationCompat.Builder mNotificationBuilder;
	
	RemoteViews mRemoteViews;
	
	public ControlNotification(Context context) {
		// TODO Auto-generated constructor stub
		
		mNotificationBuilder = new NotificationCompat.Builder(context);
		
		mRemoteViews = new RemoteViews(context.getPackageName(), R.layout.notification);
		
		mNotificationBuilder.setContent(mRemoteViews);
		
		mNotificationBuilder.setContentIntent(PendingIntent.getActivity(context, REQUEST_CODE_ENTRY_ACTIVITY, new Intent(context, EntryActivity.class), PendingIntent.FLAG_CANCEL_CURRENT));
		mRemoteViews.setOnClickPendingIntent(R.id.notification_previous, PendingIntent.getBroadcast(context, REQUEST_CODE_CONTROL, new Intent(PlayerService.BROADCAST_PREVIOUS), PendingIntent.FLAG_CANCEL_CURRENT));
		mRemoteViews.setOnClickPendingIntent(R.id.notification_toggle, PendingIntent.getBroadcast(context, REQUEST_CODE_CONTROL, new Intent(PlayerService.BROADCAST_TOGGLE), PendingIntent.FLAG_CANCEL_CURRENT));
		mRemoteViews.setOnClickPendingIntent(R.id.notification_next, PendingIntent.getBroadcast(context, REQUEST_CODE_CONTROL, new Intent(PlayerService.BROADCAST_NEXT), PendingIntent.FLAG_CANCEL_CURRENT));
		
	}
	
	public void SetTitle(String title) {
		
		mRemoteViews.setTextViewText(R.id.notification_title, title);
		
	}
	
	public void SetArtist(String artist) {
		
		mRemoteViews.setTextViewText(R.id.notification_artist, artist);
		
	}
	
	public void SetStatus(int status) {
		
		switch(status) {
		case PlayerService.STATUS_PLAYING:
			mRemoteViews.setImageViewResource(R.id.notification_toggle, android.R.drawable.ic_media_pause);
			break;
		case PlayerService.STATUS_PAUSING:
			mRemoteViews.setImageViewResource(R.id.notification_toggle, android.R.drawable.ic_media_play);
			break;
		}
		
	}
	
	public Notification GetNotification() {
		
		Notification notification = mNotificationBuilder.build();
		notification.icon = R.drawable.ic_launcher;
		//notification.flags = Notification.FLAG_NO_CLEAR;
		
		return notification;
	}
	
}
